package com.lavida.project.system.goods.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lavida.common.utils.security.ShiroUtils;
import com.lavida.framework.aspectj.lang.annotation.Log;
import com.lavida.framework.aspectj.lang.enums.BusinessType;
import com.lavida.framework.web.controller.BaseController;
import com.lavida.framework.web.page.TableDataInfo;
import com.lavida.project.system.dept.domain.Dept;
import com.lavida.project.system.dept.service.IDeptService;
import com.lavida.project.system.goods.domain.SubGoods;
import com.lavida.project.system.goods.service.SubGoodsService;
import com.lavida.project.system.papers.domain.SubPapers;
import com.lavida.project.system.user.domain.User;
import com.lavida.project.system.user.service.IUserService;
@Controller
@RequestMapping("system/subgoods")
public class SubGoodsController extends BaseController{
	private String prefix = "system/subgoods";
	@Autowired
	private SubGoodsService subGoodsService;
	
	@Autowired
	private IDeptService deptService;
	@Autowired
	private IUserService userService;
	@RequiresPermissions("data:goods:view")
	@RequestMapping()
	public String goods() {
		return prefix + "/goods";
	}
	@RequiresPermissions("data:goods:list")
	@RequestMapping("/list")
	@ResponseBody
	public TableDataInfo list(HttpServletRequest request) {
		int id = Integer.valueOf(request.getParameter("id"));
		startPage();		
		List<SubGoods> selectSubGoods = subGoodsService.selectById(id);
		System.out.println(selectSubGoods);
		return getDataTable(selectSubGoods);
	}
	@RequestMapping("/getSubGoods")
	@ResponseBody
	public Map<String, Object> getSub(HttpServletRequest request) {
		Map<String,Object> result = new HashMap<String, Object>();
		int id = Integer.valueOf(request.getParameter("id"));		
		SubGoods selectSubGoods = subGoodsService.getSubgoods(id);
		System.out.println("========================"+id);
		result.put("selectSubGoods",selectSubGoods);
		return result;
	}
	@RequiresPermissions("data:goods:delete")
	@Log(title = "参数管理", businessType = BusinessType.DELETE)
	@RequestMapping("/deleteSubGoods")
	@ResponseBody
	public Map<String, Object> deleteSub(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<>();
		int id = Integer.valueOf(request.getParameter("id"));
		try {
			int sub = subGoodsService.deleteSubgoods(id);
			result.put("status", 0);
		}catch (Exception e) {
			// TODO: handle exception
			result.put("status", "20");
			result.put("msg", e);
		}
		return result;
	}
	@RequiresPermissions("data:goods:add")
	@Log(title = "参数管理", businessType = BusinessType.INSERT)
	@RequestMapping("/addSubGoods")
	@ResponseBody
	public Map<String, Object> addSub(SubGoods subGoods) {
		
		Map<String, Object> result = new HashMap<>();
		try {
			int addsub = subGoodsService.insertSubGoods(subGoods);
			result.put("status", 0);
		}catch (Exception e) {
			// TODO: handle exception
			result.put("status", "20");
			result.put("msg", e);
		}
		
		return result;
	}
	@RequiresPermissions("data:goods:update")
	@Log(title = "参数管理", businessType = BusinessType.UPDATE)
	@RequestMapping("/updateSubGoods")
	@ResponseBody
	public Map<String, Object> updateSub(SubGoods subGoods) {
		Map<String, Object> result = new HashMap<>();
		try {
			int subnumber = subGoodsService.updateSubgoods(subGoods);
			result.put("status", 0);
		}catch (Exception e) {
			// TODO: handle exception
			result.put("status", "20");
			result.put("msg", e);
		}
		return result;
	}
}
